﻿//----------------------------------------------------------------------------------------------------
// The visual turn Counter is used to display number or turns to an event.
//----------------------------------------------------------------------------------------------------

package HG.Visual
{
	import flash.display.*;
	import flash.events.*;
	import flash.utils.Timer;
	
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	import fl.transitions.TweenEvent;
	
	import flash.text.*;
	
	public class VisualTurnCounter extends VisualObject
	{
		var m_currentValue:Number;
		
		//----------------------------------------------------------------------------------------------------
		public function VisualTurnCounter()
		{
			m_currentValue = 0;
			UpdateVisual();
		}
		
		//----------------------------------------------------------------------------------------------------
		public function SetValue(val:Number)
		{
			var diff:Number = val - m_currentValue;
			
			IncrementValue(diff);
		}
		
		//----------------------------------------------------------------------------------------------------
		public function IncrementValue(val:Number)
		{
			if (val == 0)
				return;
			
			m_currentValue += val;
			UpdateVisual();
			
			
			var displayString:String = val.toString();
			
			if (val > 0)
				displayString = "+" + val.toString();
			
			Adjust.TXT_Value.text = displayString;
			
			var TF:TextFormat = Adjust.TXT_Value.getTextFormat();
			
			if (val < 0)
            	TF.color = 0xff0000;
				
			if (val > 0)
            	TF.color = 0x00ff00;
			
            Adjust.TXT_Value.setTextFormat(TF);
			
			new Tween(Adjust, "y", Strong.easeOut, 0, 50, 2, true);
			new Tween(Adjust, "alpha", Strong.easeOut, 1, 0, 3, true);
		}
		
		//----------------------------------------------------------------------------------------------------
		private function UpdateVisual()
		{
			TXT_Value.text = m_currentValue.toString();
		}
		
		//----------------------------------------------------------------------------------------------------
	}
}